<%--
  User: Shengzhao Li
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>账务搜索</title>

</head>
<body>
<%--account search result page--%>
<div id="account_search_result_page" data-role="page" class="page">
    <div data-role="header" data-theme="f">
        <a href="${contextPath}/m/dashboard" data-icon="home" data-direction="reverse" data-transition="slide">主页</a>

        <h1>账务搜索</h1>
        <a href="../overview" data-icon="arrow-l" data-transition="slideup">返回</a>
    </div>
    <div data-role="content">
        <%--hide form, for cache search conditions--%>
        <form id="account_search_data_form" action="search" style="display: none;">
            <input type="hidden" name="amount" value="${accountSearchResult.accountSearch.amount}">
            <input type="hidden" name="types" value="${accountSearchResult.accountSearch.types}">
            <input type="hidden" name="date" value="${accountSearchResult.accountSearch.date}">
            <input type="hidden" name="description" value="${accountSearchResult.accountSearch.description}">
        </form>
        <div data-role="controlgroup">
            <a href="javascript:void(0);" data-role="button" data-theme="b" id="research_link"
               data-mini="true">重新搜索</a>
            搜索到<strong class="red">${accountSearchResult.totalSize}</strong>条结果;&nbsp;
            总金额为<strong class="color-s">${accountSearchResult.totalAmount}</strong>
        </div>
        <%--search result show in here--%>
        <ul data-role="listview" id="account_search_view" data-inset="true" data-split-icon="delete"
            data-split-theme="b">
            <c:forEach items="${accountSearchResult.list}" var="account">
                <li data-theme="${account.style.label}">
                    <a href="../details/${account.guid}" data-transition="pop">
                        <h3 class="${account.income?'red':''}">${account.typeName}
                            <c:if test="${not account.publicity}">
                                <img src="../../../images/mobile/lock.png" alt="private"/>
                            </c:if></h3>

                        <p><strong>${account.amount}</strong></p>

                        <p>${account.description} </p>

                        <p class="ui-li-aside">${account.accountDate}</p>
                    </a>
                    <c:if test="${account.allowEdit}">
                        <a href="../delete_confirm/${account.guid}" data-transition="slidedown">删除</a>
                    </c:if>
                </li>
            </c:forEach>
            <c:if test="${empty accountSearchResult.list}">
                <li>
                    <div class="ui-grid-a">
                        <div class="ui-block-a">搜索结果为空.</div>
                        <div class="ui-block-b">&nbsp; </div>
                    </div>
                </li>
            </c:if>
        </ul>
        <c:if test="${accountSearchResult.showMore}">
            <div data-role="controlgroup" id="more_div">
                <a href="javascript:void(0);" id="more_link" data-role="button" class="color-b">
                    更多 (<span
                        id="page_number">${accountSearchResult.pageNumber}</span>/${accountSearchResult.totalPages})
                    <img id="more_loading" src="${contextPath}/images/public/load.gif" alt="loading" class="more-img"/>
                </a>
            </div>
        </c:if>

    </div>
    <script type="text/javascript">

        $("div#account_search_result_page").bind('pagecreate', function () {
            var pageNumber = ${accountSearchResult.pageNumber};
            var totalSize = ${accountSearchResult.totalSize};

            $("a#more_link").bind("click", function () {
                var $this = $(this).addClass("gray");
                var nextPageNumber = (++pageNumber);
                var loading = $("#more_loading").show();
                getData();
                function getData() {
                    var url = 'more?' + $("#account_search_data_form").serialize() + "&m=" + Math.random();
                    $.ajax({
                        url:url,
                        data:{
                            pageNumber:nextPageNumber,
                            totalSize:totalSize
                        },
                        success:function (data) {
                            var listview = $("#account_search_view").append($.trim(data)).listview("refresh");
                            checkShowMore(listview);
                        }
                    });
                }

                function checkShowMore(listview) {
                    var addedSize = listview.find("li").size();
                    if (addedSize >= totalSize) {
                        $("#more_div").hide();
                    } else {
                        loading.hide();
                    }
                    $this.find("#page_number").html(nextPageNumber);
                }
            });

            $("a#research_link").bind("click", function () {
                $.mobile.changePage("init", {transition:"slidedown", data:$("#account_search_data_form").serialize()});
                return false;
            });
        });

    </script>
</div>
</body>
</html>